﻿﻿using Corp.Proj.DALFactory;
using Corp.Proj.IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Corp.Proj.BLL
{
    public abstract class BaseService<T>
        where T : class, new()
    {
        protected IBaseDal<T> m_CurrentDal;

        public BaseService()
        {
            SetCurrentDal();
        }

        protected abstract void SetCurrentDal();

        protected IDbSession DbSession
        {
            get
            {
                return DbSessionFactory.GetDbSession();
            }
        }

        // 单增、单删、单改、单查、各种查询、各种逻辑，如果可以抽象出一些可以添加
        public virtual int Add(T entity)
        {
            this.m_CurrentDal.Add(entity);
            return this.DbSession.SaveChanges();
        }

    }
}
